#ifndef Scenic_Renderer_HQAAPolygonRenderer_h
#define Scenic_Renderer_HQAAPolygonRenderer_h


#include "PolygonRenderer.h"


namespace Scenic
{
namespace Renderer
{

class FilterKernel : public Resource
{
	int size;
	int depth;
	double *lookupTable;
public:
	VolumeTexture *texture;
	
	FilterKernel(double (*func)(double, double, void *), void *data);
	~FilterKernel();

	static FilterKernel *get(int id);

	void createTexture();
};

class HQAAPolygonRenderer : public PolygonRenderer
{
	Context *context;
	int color;

	VertexStore *buffer;
	VertexStore *vs;
	VertexStore *addVs;
	VertexStore *subVs;

	TessVertex *triangle[3];
	bool triangleEdge[3];
	bool edgeState;
	int corner;
	double filterLength;
	Double2 filterSize;
	FilterKernel *kernel;

public:
	HQAAPolygonRenderer(Context *context);
	~HQAAPolygonRenderer();

	void begin();
	void end();
	void addPoint(double x, double y);
	void addTriangle(int vertex1, bool edge1, int vertex2, bool edge2, int vertex3, bool edge3);
private:
	void draw();
	void processTriangle();
	void drawEdge(TessVertex *v1, TessVertex *v2);
	void drawCorner(Double2 p, double tableZ, double mx, double my, double diffuse);
	void setLookupTableCoordinates(int x, int y, double z, double *p);
};

}
}

#endif
